package com.jason.bookworm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jason.bookworm.dao.mapper.BookClassifyMapper;
import com.jason.bookworm.dao.pojo.BookClassify;
import com.jason.bookworm.service.BookClassifyService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 分类相关方法
 * @author YANGKUN
 */
@Service
public class BookClassifyServiceImpl implements BookClassifyService {

    @Resource
    private BookClassifyMapper bookClassifyMapper;
    /**
     * 获得所有分类
     *
     * @return
     */
    @Override
    public List<BookClassify> getAllBookClassify() {
        QueryWrapper<BookClassify> queryWrapper = new QueryWrapper<>();
        return bookClassifyMapper.selectList(queryWrapper);
    }

    /**
     * 获取某个分类
     *
     * @param classifyId
     * @return
     */
    @Override
    public BookClassify getBookClassify(String classifyId) {
        QueryWrapper<BookClassify> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("bc_id",Integer.parseInt(classifyId));
        return bookClassifyMapper.selectOne(queryWrapper);
    }

    /**
     * 删除某个分类(物理删除)
     * @param bookClassify
     */
    @Override
    public void deleteBookClassify(BookClassify bookClassify) {
        QueryWrapper<BookClassify> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("bc_id",bookClassify.getId());
        bookClassifyMapper.delete(queryWrapper);
    }

    /**
     * 新增分类
     * @param bookClassify
     */
    @Override
    public void AddNewBookClassify(BookClassify bookClassify) {
        bookClassifyMapper.insert(bookClassify);

    }
}
